package org.zjh.view.findpassword;

import org.zjh.controller.action.CancelJbtLis;
import org.zjh.controller.listener.ConfirmFindWayJbtLis;

import javax.swing.*;
import java.awt.*;
import static org.zjh.constant.ImageConstant.FIND_PASSWORD_WAY_IMAGE;

/**
 * 找回密码方式面板
 */
public class FindPasswordWayPanel extends JPanel {
    private JTextField accountTextField;
    private JTextField nicknameTextField;
    private JButton confirmFindWayJbt;
    private JButton cancelJbt;

    public FindPasswordWayPanel() {
        init();
        addListener();
    }


    /**
     * 初始化
     */
    private void init() {
        setLayout(null);
        //创建标签
        JLabel accountFindLabel = new JLabel("通过账号");
        JLabel nicknameFindLabel = new JLabel("通过昵称");
        JLabel choiceLabel = new JLabel("任选一种方式输入");

        //设置标签属性
        accountFindLabel.setBounds(100, 50, 100, 50);
        nicknameFindLabel.setBounds(100, 100, 100, 50);
        choiceLabel.setBounds(100, 10, 200, 50);

        //设置字体
        accountFindLabel.setFont(new Font("黑体", Font.PLAIN, 25));
        nicknameFindLabel.setFont(new Font("黑体", Font.PLAIN, 25));
        choiceLabel.setFont(new Font("黑体", Font.PLAIN, 25));

        //字体加粗
        accountFindLabel.setForeground(Color.BLACK);
        nicknameFindLabel.setForeground(Color.BLACK);
        choiceLabel.setForeground(Color.BLACK);

        //创建输入框
        accountTextField = new JTextField();
        nicknameTextField = new JTextField();

        //设置输入框属性
        accountTextField.setBounds(200, 60, 100, 25);
        nicknameTextField.setBounds(200, 110, 100, 25);

        //创建按钮
        confirmFindWayJbt = new JButton("确定");
        cancelJbt = new JButton("取消");
        //按钮属性设置
        confirmFindWayJbt.setBounds(100, 150, 100, 25);
        cancelJbt.setBounds(250, 150, 100, 25);

        //添加
        add(accountFindLabel);
        add(nicknameFindLabel);
        add(choiceLabel);
        add(accountTextField);
        add(nicknameTextField);
        add(confirmFindWayJbt);
        add(cancelJbt);
    }


    /**
     * 添加监听器
     */
    private void addListener() {
        //设置动作指令
        cancelJbt.setActionCommand("findPasswordWayCancel");
        //添加动作监听器
        cancelJbt.addActionListener(CancelJbtLis.getInstance());
        //添加确定按钮监听器
        confirmFindWayJbt.addMouseListener(new ConfirmFindWayJbtLis());
    }

    public void refresh(){
        accountTextField.setText("");
        nicknameTextField.setText("");
    }



    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.drawImage(FIND_PASSWORD_WAY_IMAGE.getImage(), 0, 0, FIND_PASSWORD_WAY_IMAGE.getIconWidth(), FIND_PASSWORD_WAY_IMAGE.getIconHeight(), null);
    }


    public JTextField getAccountTextField() {
        return accountTextField;
    }

    public JTextField getNicknameTextField() {
        return nicknameTextField;
    }


}
